/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.wider.foundation.models;

import com.wider.foundation.nxfile.NxFS;
import java.io.File;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;

/**
 * This class extends the DefaultMutableTreeNode to support:
 * 1) ToString returns on the filename instead of full path
 * 2) Network extended
 * 3) Seperating files-in-path from nodes of mixed files/folder to a List
 * 4) Temporarily empty node with user-specific message
 * 
 * @author William Choi <avextk@gmail.com>
 */
public class NxFileTreeNode extends DefaultMutableTreeNode {

    private boolean             dironly;
    private boolean             isflder;
    private NxFS                filesys;
    private DefaultTableModel   filelst;

    /**
     * Default constructor for creating instance of Tree Node for File that representing an native abstract path.
     * @param node      The abstract path to be carried by this node
     */
    public NxFileTreeNode(File node){
        super(node);
        filesys = null;
        commInits();
    }

    /**
     * Constructor for user to create instance of Tree Node for File that representing a remote abstract path.
     * @param node      The abstract path to be carried by this node
     * @param fs        The file system in NxFS class for which the node relies.
     */
    public NxFileTreeNode(File node, NxFS fs){
        super(node);
        filesys = fs;
        commInits();
    }


    @Override
    public boolean isLeaf(){
        if  (isDirectory())
            return false;

        return (0 == this.getChildCount());
    }

    @Override
    public String toString(){
        return getFile().getName();
    }

    public boolean isDirectory(){
        return isflder;
    }

    public String getPathString(){
        return getFile().toString();
    }

    //TODO: Set FS provider?
    /**
     * List the first level sub-folders under this node.
     *
     * @return True if structure change on the sub-tree of this node; False otherwise.
     */
    public boolean listFolders(){
        boolean ret = false;

        return ret;
    }

    public boolean listFiles(){
        boolean ret = false;

        return ret;    
    }

    /*
     * Private Methods
     */
    private void commInits(){
        dironly = true;
        filelst = null;
    }

    private File getFile(){
        return (File) super.getUserObject();
    }
}
